#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

#include "single_list.h"

void list_for_each(struct list *head)
{
    for(struct list *pTmp = head->next;pTmp;pTmp = pTmp->next)
    {
        printf("%p\r\n",pTmp);
    }
}

struct list *list_new(void)
{
    return (struct list *)malloc(sizeof(struct list));
}

struct list head = {NULL};

struct addr_t {
	int val;
	struct list link;
};

int main(int argc,char *argv[])
{
	struct addr_t *tmp;
	struct addr_t *insert;

	insert = (struct addr_t *)malloc(sizeof(struct addr_t));
	insert->val = 1;
	list_add_head(&head, &insert->link);
	list_for_each_entry(tmp, &head, link)
	{
		printf("%d ", tmp->val);
	}printf("\r\n");
    list_del(&head, &insert->link);
	list_for_each_entry(tmp, &head, link)
	{
		printf("%d ", tmp->val);
	}printf("\r\n");

	insert = (struct addr_t *)malloc(sizeof(struct addr_t));
	insert->val = 2;
	list_add_head(&head, &insert->link);
	list_for_each_entry(tmp, &head, link)
	{
		printf("%d ", tmp->val);
	}printf("\r\n");

	insert = (struct addr_t *)malloc(sizeof(struct addr_t));
	insert->val = 3;
	list_add_tail(&head, &insert->link);
	list_for_each_entry(tmp, &head, link)
	{
		printf("%d ", tmp->val);
	}printf("\r\n");
    list_del(&head, &insert->link);
	list_for_each_entry(tmp, &head, link)
	{
		printf("%d ", tmp->val);
	}printf("\r\n");

	list_del_head(&head);
	list_for_each_entry(tmp, &head, link)
	{
		printf("%d ", tmp->val);
	}printf("\r\n");

	list_del_tail(&head);
	list_for_each_entry(tmp, &head, link)
	{
		printf("%d ", tmp->val);
	}printf("\r\n");

	list_del_head(&head);
	list_for_each_entry(tmp, &head, link)
	{
		printf("%d ", tmp->val);
	}printf("\r\n");

	if(list_is_empty(&head))
	{
		printf("empty\r\n");
	}

	return 0;
}

/*
int main(int argc,char *argv[])
{
    if(!list_is_empty(&head))
    {
        list_del_head(&head);
    }
    printf("------------\r\n");

    struct list *insert = list_new();
    list_add_tail(&head,insert);
    list_for_each(&head);
    printf("------------\r\n");

    struct list *insert1 = list_new();
    list_add_head(&head,insert1);
    list_for_each(&head);
    printf("------------\r\n");

    struct list *insert2 = list_new();
    list_add_tail(&head,insert2);
    list_for_each(&head);
    printf("------------\r\n");

    struct list *insert3 = list_new();
    list_add_tail(&head,insert3);
    list_for_each(&head);
    printf("------------\r\n");

    list_del_head(&head);
    list_for_each(&head);
    printf("------------\r\n");

    list_del_tail(&head);
    list_for_each(&head);
    printf("------------\r\n");

    list_del_tail(&head);
    list_for_each(&head);
    printf("------------\r\n");

    return 0;
}
*/
